#include <stdio.h>

#define N 10
#define INF 10000000

int w_min; //best weight
int c[N][N],w[N][N];
int trace[N],trace_tmp[N];
int n,m,d;
void readin(int[N][N]);
void traceback(int,int,int);


int main()
{
	scanf("%d%d%d",&n,&m,&d);
	readin(c);
	readin(w);
	w_min = INF;
	traceback(0,0,0);
	printf("%d\n",w_min);
	for (int i = 0; i < n; ++i)
	{
		printf("%d ",trace[i]+1);
	}
	printf("\n");
	return 0;
}

void readin(int mat[N][N])
{
	for(int i=0;i<n;++i)
	{
		for(int j = 0;j<m;++j)
		{
			scanf("%d",&mat[i][j]);
		}
	}
}

void traceback(int id,int cost,int weight)
{
	if(cost > d || weight > w_min) return;
	if(id == n)
	{
		if(weight < w_min)
		{
			for(int i=0;i<n;++i) trace[i] = trace_tmp[i];
			w_min = weight;
		}
		return ;
	}
	for(int i=0;i<m;++i)
	{
		trace_tmp[id] = i;
		traceback(id+1,cost+c[id][i],weight+w[id][i]);
	}
}